﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using iTunesLib;
using System.Threading;
using System.IO;
using System.Drawing;

namespace jukebox_player
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            iTunesApp iTunes = new iTunesApp();
            //iTunes.Pause();
            //iTunes.Play();
            int count  = iTunes.LibraryPlaylist.Tracks.Count;
            iTunes.VisualsEnabled = true;
            iTunes.FullScreenVisuals = true;
            //count++;
            //iTunes.SoundVolume /= 2;
            for (int i = 1; i <= count; i++)
            {
                iTunes.LibraryPlaylist.Tracks[i].Play();
                Thread.Sleep(6000);
            }
            
            /*iTunes.CurrentTrack.Artwork[1].SaveArtworkToFile("C:\\");
            try
            {
                int darp = iTunes.CurrentTrack.Artwork.Count;
                iTunes.CurrentTrack.Artwork[1].SaveArtworkToFile("C:\\");
            }
            catch (Exception e)
            {
                string darp = e.ToString();
            }*/

            try
            {
                IITArtworkCollection Art1 = iTunes.CurrentTrack.Artwork;

                IITArtwork Art2 = Art1[1];
                Console.WriteLine(Art1.Count);

                Art2.SaveArtworkToFile(@"c:\users\dan\desktop\Album.jpg");

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }

            iTunes.Stop();

            //Stream r = File.Open("c:\\GARP\\Album.jpg", FileMode.Open);

            //Image temp = FromStream(r);

            //r.Close();

            //pictureBox1.Image = temp;

            //SetImage(pictureBox1);

            this.Visibility = System.Windows.Visibility.Hidden;
        }
    }
}
